package dr.server.impl.mail;

import dr.common.ResultModel;
import dr.common.utils.JMailUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class JMailService {

    @Autowired
    JMailUtil jMailUtil;

    public ResultModel send(String msgType, String title, String to, String messageOrTemplate, String filepath) {
        try {
            switch (msgType) {
                case "1":
                    jMailUtil.sendSimpleMail(to, title, messageOrTemplate);
                    break;
                case "2":
                    jMailUtil.sendHtmlMail(to, title, messageOrTemplate);
                    break;
                case "3":
                    jMailUtil.sendAttachmentsMail(to, title, messageOrTemplate, filepath);
                    break;
            }
            return ResultModel.ok();
        }catch (Exception e){
            return ResultModel.fail(e.getLocalizedMessage());
        }
    }
}
